package com.example.fragment.tool;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.fragment.R;


public class ShowDownloadDialog extends Dialog implements View.OnClickListener{


    private TextView textView;
    private ProgressBar progressBar;
    private String title;
    public Float chazhi;
    private int settemp=0;
    private boolean isFiret=true;
    private IOnButton onButton;

     Button button;
    public ShowDownloadDialog(@NonNull Context context) {
        super(context);
    }

    public ShowDownloadDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    protected ShowDownloadDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    public ProgressBar getProgressBar() {
        return progressBar;
    }

    public void setProgressBar(ProgressBar progressBar) {
        this.progressBar = progressBar;
    }

    public TextView getTextView() {
        return textView;
    }
    public void setTitle(String title){
        this.title=title;
    }
    public void setButtonOnclick(IOnButton buttonOnclick) {
      this.onButton=buttonOnclick;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.progress_dialog);
        progressBar =findViewById(R.id.updateProgress);
        textView=findViewById(R.id.progress_title);
        button =findViewById(R.id.btn_negetive);
        button.setVisibility(View.INVISIBLE);
        if (!TextUtils.isEmpty(title)){
            textView.setText(title);
        }
        button.setOnClickListener(this);
        progressBar.setMax(100);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_negetive:
                if(onButton!= null){
                    onButton.onButtonclick(this);
                }
                dismiss();
                break;
        }
    }
    public Button setOnButton1() {
      return button.findViewById(R.id.btn_negetive);
    }
    public void setprogressBar(){

    }
    public int getSettemp() {
        return settemp;
    }
    public void setProgress1(int nowtem){//设置进度条
        if(isFiret){
            float chazh= Float.valueOf(settemp-nowtem);
            chazhi=Math.abs(chazh);
            this.isFiret=false;
        }
        float set123=Float.valueOf(settemp-nowtem);
        float chazhinow=chazhi-Math.abs(set123);
        float percentage=chazhinow/chazhi;
        int progress= (int) (percentage*100);
        progressBar.setProgress(progress);
    }
    public void setSettemp(int settemp) {
        this.settemp = settemp;
    }
    public interface IOnButton{
        void onButtonclick(ShowDownloadDialog showDownloadDialog);
    }
}
